package com.show.task;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.show.business.device.bean.UartTmp;
import com.show.business.device.mapper.DeviceAlarmMapper;
import com.show.business.device.mapper.UartTmpMapper;
import com.show.business.device.service.IDeviceAlarmService;
import com.show.business.device.service.IUartTmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 设备告警定时任务处理
 * @author ccx
 */
@Slf4j
@Component("deviceAlarmTask")
public class DeviceAlarmTask {

    @Resource
    private IDeviceAlarmService deviceAlarmService;

    @Resource
    private IUartTmpService uartTmpService;
    /**
     * 同步设备告警数据（在第 0 秒 触发。每 1分钟 执行一次）
     */
    @Transactional(rollbackFor = Exception.class)
    public void syscUartTmp() {
        log.info("deviceAlarmTask_syscUartTmp开始执行，时间：{}", DateUtil.now());
        List<UartTmp> list =  uartTmpService.getList();
        if(list != null && list.size() > 0){
            for(UartTmp tmp : list){
                //同步设备报警数据
                deviceAlarmService.saveInfo(tmp);
                //更新远数据同步状态
                uartTmpService.updateUartTmpMark(tmp.getId());
            }
        }
        log.info("deviceAlarmTask_syscUartTmp结束执行，时间：{}", DateUtil.now());
    }

}
